package servlets;

import java.io.IOException;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class PlayQuiz
 */
public class PlayQuiz extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PlayQuiz() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String qType = (String)request.getParameter("QuizType");
		//System.out.println(qType);
		Vector<Integer> QList = new Vector<Integer>();
		if(qType.equals("Sample"))
		{
			System.out.println("Topic attribute set to CS");
			request.getSession().setAttribute("Topic", "Computer Science");
			request.getSession().setAttribute("SubTopic", null);
			request.getSession().setAttribute("ExactTopic", null);

		}
		else
		{
			request.getSession().setAttribute("Topic", request.getParameter("Topic"));
			System.out.println(request.getParameter("SubTopic"));
			if(request.getParameter("SubTopic").length()>0)
			request.getSession().setAttribute("SubTopic", request.getParameter("SubTopic"));
			if(request.getParameter("SubTopic").length()>0)
			request.getSession().setAttribute("ExactTopic", request.getParameter("ExactTopic"));

		}
		request.getSession().setAttribute("score", 0);
		request.getSession().setAttribute("QNum", 1);
		request.getSession().setAttribute("QList", QList);
		
					
		RequestDispatcher RequestDispatcherObj =request.getRequestDispatcher("/view/BeginGame.jsp");
        RequestDispatcherObj.forward(request, response);
	}

}
